package ch.yoursource.StartPageBuilder;

import java.util.Properties;

//TODO
public class PropertiesHandler {
    public static String propertiesFile = "./props.txt";
    private Properties props = new Properties();
    
    public PropertiesHandler() {
        this.loadShortcuts();
    }
    public String[][] getShortcuts() {
        return stringToShortcuts(props.getProperty("shortcuts"));//TODO
    }
    public void saveShortcuts(String[][] shortcuts) {
        props.setProperty("shorcuts",shortcutsToString(shortcuts));
    }
    private void loadShortcuts() {
        
    }
    private String shortcutsToString(String[][] shortcuts) {
        StringBuilder str = new StringBuilder();
        for(int i = 0;i<shortcuts.length;i++) {
            String[] entry = shortcuts[i];
            for(int j = 0;j<5;j++) {
                str.append(entry[j]+";");
            }
            if(i+1<shortcuts.length) {
                str.append("\n");
            }
        }
        return str.toString();
    }
    private String[][] stringToShortcuts(String prop) {
        String[] lines = prop.split("\n");
        String[][] shortcuts = new String[lines.length][5];
        for(int i=0;i<lines.length;i++) {
            for(int j=0;j<lines[i].length();j++){
                shortcuts[i][j]=lines[i].split(";")[j];
            }
        }
        return shortcuts;
    }
    //TODO
}
